package com.webchat.ugc.service.moment;


import com.webchat.domain.vo.request.MomentSaveOrUpdateVO;
import com.webchat.ugc.repository.dao.IMomentLinkDAO;
import com.webchat.ugc.repository.dao.IMomentMediaDAO;
import com.webchat.ugc.repository.entity.MomentLinkEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MomentLinkService {


    @Autowired
    private IMomentLinkDAO momentLinkDAO;



    public boolean saveMomentLink(Long momentId,
                                  MomentSaveOrUpdateVO momentSaveOrUpdate) {
        if (!momentSaveOrUpdate.includeLink()) {
            return true;
        }
        String link = momentSaveOrUpdate.getLink();
        MomentLinkEntity momentLink = momentLinkDAO.findById(momentId).orElse(null);
        if (momentLink != null) {
            momentLink.setResource(link);
        } else {
            momentLink = new MomentLinkEntity();
            momentLink.setMomentId(momentId);
            momentLink.setResource(link);
        }
        momentLinkDAO.save(momentLink);
        return true;
    }


    public MomentLinkEntity getLink(Long momentId) {
        return momentLinkDAO.findAllByMomentId(momentId);
    }
}
